package com.xcity.game.player;

import java.util.Collection;

import org.slf4j.Logger;

import com.xcity.db.entity.Player;

import naga.x.App;

public class SaveOnlinePlayersOperation implements Runnable {

	protected int tick;
	protected static final Logger LOG = PlayerService.LOG;
	
	@Override
	public void run() {
		Collection<Player> vals = App.getApp().getServiceManager().get(PlayerService.class).getOnlinePlayers();
		if (vals.isEmpty()) {
			return;
		}
		for (Player player : vals) {
			if (player.getId() % 10 == tick) {
				player.save();
				LOG.info("[PLAYER SAVE]ID[{}]NAME[{}]LVL[{}]EXP[{}]GOLD[{}]STONE[{}]AUTO", player.getId(), player.getName(), player.getLevel(), player.getExp(), player.getGold(), player.getStone());
			}
		}
		if (++tick == 10) {
			tick = 0;
		}
	}

}
